<%@ page import="java.util.ArrayList,teamCservlets.DefectBean,teamCservlets.PersonBean,teamCservlets.ApplicationBean" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Team C Defect System</title>
</head>

<%-- The "user" attribute, from the session, identifies the currently 
logged-in user, if any.  If the user's ID is -1, that indicates the
object isn't a valid user. --%>
<jsp:useBean id="user" type="teamCservlets.PersonBean" scope="session"/>

<%
String output;
if ((user == null) || (user.getId() == -1)) { 
	// No valid user object in the session, so the user must login
	response.sendRedirect("login.jsp");
}
%>

<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">Team C Defect System</H1>
<table width="100%">
	<tr><td><p style="font-size:150%">Defect List</p></td>
		<td align="right">You are logged in as
		<%= user.getFirstName() %> <%= user.getLastName() %>
	<FORM action="loginlogout">
		<INPUT TYPE="SUBMIT" NAME="logoutButton" Value="Logout">
	</FORM> 
		</td></tr>
	<tr><td></td><td align="right"></td></tr>
</table>

<FORM action="defectforms">
<fieldset><legend>Open defects:</legend>
<table>
		<tr><td align="left" colspan="2">
		<select name="defectId" size="20" width="400px" style="font-size:75%">

			<%-- Populate the Defect list.  This inserts the defect ID 
			into the "value" and the defect name into the displayed list item.  When the user selects
			a row and sends the form back to the servlet, the "value" will be retrieved, and this
			will be the defect ID. --%>
			<%
				ArrayList<DefectBean> openDefects = (ArrayList<DefectBean>)request.getAttribute("defectList");
				for (DefectBean defect : openDefects) {
					String defectRow = "ID:" + defect.getDefectID() + ", " + 
						"Status:" + defect.getStatus() + ", " +
						"Priority:" + defect.getPriority() + ", " +
						defect.getSummary();
			%>
					<option value="<%= defect.getDefectID() %>"><%= defectRow %>
			<%
				}
			%>


		</select></td></tr>
		<tr><td align="left">	
			<INPUT TYPE="SUBMIT" NAME="btnDisplayDefect" Value="Display Defect">
			<INPUT TYPE="SUBMIT" NAME="btnEmailDefect" Value="Email Defect Info">
		<tr>
		<td>
		<strong style="color:red;font-size:125%"><%=
			request.getAttribute("defectlistmessage")
		%></strong>
		</td>
		</tr>
</table>
</fieldset>		
</FORM>

<form action="defectforms">
	<p align="center"><input align="center" type="submit" name="btnCreateDefect" Value="Create New Defect"></p>
</form>

</BODY></HTML>
